from llama_index.core import ServiceContext, VectorStoreIndex
from llama_index.embeddings.huggingface import HuggingFaceEmbedding

# 加载中文嵌入模型（BAAI/bge-base-zh）
embed_model = HuggingFaceEmbedding("BAAI/bge-base-zh")
service_context = ServiceContext.from_defaults(embed_model=embed_model)
# 构建向量索引并创建查询引擎
index = VectorStoreIndex.from_documents(
   documents,
   service_context=service_context
)
query_engine = index.as_query_engine(similarity_top_k=3)  # 取Top3相似文档
response = query_engine.query("如何申请年度休假？")  # 执行查询